package de.hfu.model;

import java.io.Serializable;
import java.util.Date;

import de.hfu.helper.DataAccess;
import de.hfu.helper.Helper;

public class Dish implements Comparable<Dish>, Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -7030781413749559005L;
	private String title;
	private String description;
	private String title_en;
	private String description_en;
	private String comment;
	private float rating;
	private Date date;
	private boolean postedComment;
	private boolean postedRating;
	
	public Dish() {
		title = "";
		title_en = "";
		description = "";
		description_en = "";
		comment = "";		
		rating = 0;
		date = null;
		postedComment = true;
		postedRating = true;
	}

	public Dish(String title) {
		this();

		this.title = title;
		this.title_en = title;
	}

	public void setDescription(String description) {
		this.description = description;
		this.description_en = description + "\n(Need Internet to translate)";
	}

	public String getDescription(String language) {
		if (language.compareToIgnoreCase(DataAccess.DEFAULT_LANGUAGE) == 0)
			return this.description;
		return this.description_en;		
	}

	public void setRating(float rating) {
		this.rating = rating;
	}

	public float getRating() {
		return this.rating;
	}

	public String getTitle(String language) {
		if (language.compareToIgnoreCase(DataAccess.DEFAULT_LANGUAGE) == 0)
			return title;
		else
			return title_en;
	}
	
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
		this.title_en = title;
	}

	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public void setTitle_en(String title_en) {
		this.title_en = title_en;
	}
	
	public void setDescription_en(String description_en) {
		this.description_en = description_en;
	}
	
	@Override
	public int compareTo(Dish o) {
		int tmp = 0;

		tmp = this.date.compareTo(o.date);
		if (tmp != 0)
			return tmp;

		tmp = this.title.compareTo(o.title);

		return tmp;
	}

	@Override
	public boolean equals(Object o) {
		Dish tmp = (Dish) o;
		return Helper.isEqual(this.date, tmp.date) && this.title.equalsIgnoreCase(tmp.title);
	}
	
	@Override
	public String toString() {
		return this.title + "\n" + this.description + "\n" + "OverallRating: "
				+ this.rating + "\n" + "My comment: " + this.comment;
	}

	public boolean isPostedComment() {
		return postedComment;
	}

	public void setPostedComment(boolean postedComment) {
		this.postedComment = postedComment;
	}

	public boolean isPostedRating() {
		return postedRating;
	}

	public void setPostedRating(boolean postedRating) {
		this.postedRating = postedRating;
	}
}
